<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Project extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
 }
 function index(){ 	 	 
	 //phan trang
 	 $config['base_url'] = base_url().'project/index'; 
	 $config['total_rows'] = $this->muser->num_rows('Project');
	 
	 $config['per_page'] = 10; // xác định số record ở mỗi trang  
     $config['uri_segment'] = 3; // xác định segment chứa page number  
	 $this->pagination->initialize($config); 
	 $data['result']=$this->muser->getalldata('Project',$config['per_page'],$this->uri->segment(3));
	 		 
	 $data['project']=$this->getLabID();
	 $this->load->view('_header');
     $this->load->view('project/project_view',$data); 
     $this->load->view('_footer');
 }
	
	function insert()
	{
			$DT['ProjectName']=$this->input->post('ProjectName');
			$DT['BeginDate']=$this->input->post('BeginDate');
			$DT['EndDate']=$this->input->post('EndDate');
			$DT['Lab_ID']=$this->input->post('Lab_ID');
			if ($DT['BeginDate']>$DT['EndDate']) {
				$data['error']='Begin Date more than End Date';
			}else
				{
					$this->muser->addData('Project',$DT);
					$data['error']='insert successful!';
				}						
			redirect('project/index');	
	}
	
 function delete($Project_ID){
	$this->muser->delColumn('Project','Project_ID',$Project_ID);
	redirect('project/index');
 }
function edit1 ()
 {
 	$DT['Project_ID']=$this->input->post('Project_ID');	
	$DT['ProjectName']=$this->input->post('ProjectName');
	$DT['BeginDate']=$this->input->post('BeginDate');
	$DT['EndDate']=$this->input->post('EndDate');
	$DT['Lab_ID']=$this->input->post('Lab_ID');
	$this->muser->updateData('Project','Project_ID',$DT['Project_ID'],$DT);
	$data['error']='Edit successful!';	 	
	redirect('project/index',$data);		
 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('Project','Project_ID',$str);
	$data['result']=$result;
	$data['lab']=$this->getLabID();	
 	$this->load->view('_header');
	$this->load->view('project/editProject_view',$data);	
	$this->load->view('_footer');
 }
 
 function check_Project($str){
 		return $this->muser->checkData('Project','Project_ID',$str);		
 }
function getLabID()
	{
	$project1=$this->muser->getData('Lab');
	 foreach ($project1 as $row) 
	 {
	 			 $project[$row->Lab_ID]=$row->Lab_ID.'-'.$row->LabName;
	 }
	 return $project;
	}	
}